<style>
    .usageDetailsTableBox {
        height: 100px;
        overflow: hidden;
        margin: 10px 0 20px;
    }

    .usageDetailsTableBox > .layui-table,
    .usageDetailsTableBox > .layui-table-view {
        margin: 0;
    }

    .usageDetailsTitle {
        height: 22px;
        margin-bottom: 15px;
        padding-left: 20px;
    }

    .usageDetailsTitle > span {
        line-height: 22px;
        font-size: 20px;
    }

    .timeline {
        width: 75%;
        margin: 30px auto 0;
    }

    .timeline-list {
        position: relative;
        padding-bottom: 40px;
    }

    .timeline-list:before {
        content: "";
        position: absolute;
        left: 123px;
        top: 0;
        z-index: 0;
        height: 100%;
        border-left: 1px dotted #ccc;
    }

    .timeline-list:first-child:before {
        height: calc(100% - 30px);
        top: 32px;
    }

    .timeline-list:first-child .timeline-item-time {
        color: #000000;
    }

    .timeline-list:first-child .timeline-item-icon {
        background: #009C5E;
        box-shadow: 0 0 2px 2px #009C5E;
    }

    .timeline-list:first-child .timeline-item-box {
        border: 1px solid #009C5E;
        background: rgba(0, 156, 94, 0.1);
    }

    .timeline-list:first-child .timeline-item-box * {
        color: #009C5E;
    }


    .timeline-list:last-child:before {
        height: 30px;
    }

    .timeline-item {
        display: flex;
        align-items: baseline;
    }

    .timeline-item-time {
        width: 90px;
        font-size: 16px;
        font-weight: 400;
        color: #999999;
        line-height: 19px;
        text-align: right;
    }

    .timeline-item-icon {
        width: 10px;
        height: 10px;
        background: #CCCCCC;
        border-radius: 50%;
        margin-left: 29px;
        margin-right: 29px;
    }

    .timeline-item-box {
        flex: 1;
        padding: 15px 10px;
        background: rgba(204, 204, 204, 0.1);
        border-radius: 2px 2px 2px 2px;
        border: 1px solid #CCCCCC;
    }

    .timeline-item-inline {
        display: inline-block;
        margin-right: 20px;
        font-family: Microsoft YaHei-Regular, Microsoft YaHei;
        font-weight: 400;
    }

    .timeline-item-black {
        color: #333333;
    }

    .timeline-item-grey {
        color: #999999;
    }
</style>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">刀具条码：</label>
                                    <div class="layui-input-inline">
                                        <input name="packLabelCode" class="layui-input" type="text" placeholder="请输入刀具条码"
                                               autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">物料编号：</label>
                                    <div class="layui-input-inline">
                                        <input name="skuCode" class="layui-input" type="text" placeholder="请输入物料编号"
                                               autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">物料名称：</label>
                                    <div class="layui-input-inline">
                                        <input name="skuName" class="layui-input" type="text" placeholder="请输入物料名称"
                                               autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">规格码：</label>
                                    <div class="layui-input-inline">
                                        <input name="specCode" class="layui-input" type="text" placeholder="请输入规格码"
                                               autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">领新人：</label>
                                    <div class="layui-input-inline">
                                        <input name="usherInName" class="layui-input" type="text" placeholder="请输入领新人"
                                               autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">当前状态：</label>
                                    <div class="layui-input-inline">
                                        <select name="statusDesc" lay-filter=""></select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">操作人：</label>
                                    <div class="layui-input-inline">
                                        <input name="curOperatorName" class="layui-input" type="text"
                                               placeholder="请输入操作人" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">是否盘验：</label>
                                    <div class="layui-input-inline">
                                        <select name="isCheck" lay-filter=""></select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">盘验人：</label>
                                    <div class="layui-input-inline">
                                        <input name="inspectorName" class="layui-input" type="text"
                                               placeholder="请输入盘验人" autocomplete="off"/>
                                    </div>
                                </div>
                            </div>
                            <div class="query-rt">
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog"
                                            lay-submit layui-form-keyDownSearch="true">查询
                                    </button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="lay-btn-rows">
                    <div class="lay-btn-box">
                        <div class="lay-btn-lt">
                            <button class="layui-btn icon-btn color-green">导出</button>
                        </div>
                        <div class="lay-btn-rt">

                        </div>
                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="lifeCycleTable" lay-filter="lifeCycleTable"></table>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="lifeCycleTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="info">使用详情</a>
</script>

<!--使用详情弹窗-->
<script type="text/html" id="usageDetailsTemplate">
    <div lay-filter="usageDetailsForm" class="layui-form model-form"
         style="padding: 0 20px;height: 100%;overflow: hidden;">
        <div class="layui-tab usageDetailsTableBox">
            <table class="layui-table" id="usageDetailsTable" lay-filter="usageDetailsTable"></table>
        </div>
        <div class="usageDetailsTitle">
            <i class="layui-icon layui-icon-log" style="display: inline; font-size: 22px; color: #009C5E;"></i>
            <span>生命周期记录表</span>
        </div>
        <div class="open-details-box" style="height: calc(100% - 220px); overflow-y: scroll;" id="timeline">>
            <!--<ul class="timeline">
                <li class="timeline-list">
                    <div class="timeline-item">
                        <div class="timeline-item-time">2023-08-14 14:25:59</div>
                        <div class="timeline-item-icon"></div>
                        <div class="timeline-item-box">
                            <div class="timeline-item-inline">
                                <span class="timeline-item-black">盘验人：</span>
                                <span class="timeline-item-grey">刘景</span>
                            </div>
                            <div class="timeline-item-inline">
                                <span class="timeline-item-black">结果相符(报废)</span>
                            </div>
                            <div class="timeline-item-inline">
                                <span class="timeline-item-black">盘验单号：</span>
                                <span class="timeline-item-grey">OU-20230907-0003</span>
                            </div>
                        </div>
                    </div>
                </li>
            </ul>-->
        </div>
        <div class="layui-form-item text-right">
            <div class="layui-inline">
                <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            </div>
        </div>
    </div>
</script>

<script id="timeLineTemplate" type="text/html">
    <ul class="timeline">
        {{# layui.each(d, function(index, item){ }}
        <li class="timeline-list">
            <div class="timeline-item">
                <div class="timeline-item-time">{{ item.time }}</div>
                <div class="timeline-item-icon"></div>
                <div class="timeline-item-box">
                    <div class="timeline-item-inline">
                        <!--<span class="timeline-item-black">盘验人：</span>-->
                        <span class="timeline-item-grey">{{ item.content }}</span>
                    </div>
                    <!--<div class="timeline-item-inline">
                        <span class="timeline-item-black">{{ item.stateName|| '' }}</span>
                    </div>
                    <div class="timeline-item-inline">
                        <span class="timeline-item-grey">盘验单号：</span>
                        <span class="timeline-item-grey">OU-20230907-0003</span>
                    </div>-->
                </div>
            </div>
        </li>
        {{# }); }}

        {{# if(d.length === 0){ }}
        <h3 style="text-align: center;line-height: 100px">无数据</h3>
        {{# } }}
    </ul>
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin', 'upload', 'laydate', 'element'], function () {
        let $ = layui.jquery;
        let {layer, element, config, table, admin, form, laydate, laytpl, upload} = layui;

        // 渲染表格
        let insTb = table.render({
            elem: '#lifeCycleTable',
            url: config.base + 'enterprisecab/cabinet/admin/cutterLifeCycle/list',
            toolbar: true,
            defaultToolbar: ["filter"],
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers', title: '序号', fixed: 'left', width: 60}
                , {field: 'packLabelCode', sort: true, title: '刀具条码'}
                , {field: 'skuCode', sort: true, title: '物料编号'}
                , {field: 'skuName', sort: true, title: '物料名称'}
                , {field: 'specCode', sort: false, title: '规格码'}
                , {field: 'usherInName', sort: false, title: '领新人'}
                , {field: 'statusDesc', sort: false, title: '当前状态'}
                , {field: 'curOperatorName', sort: false, title: '操作人'}
                , {field: 'isCheckDesc', sort: false, title: '是否盘验'}
                , {field: 'inspectorName', sort: false, title: '盘验人'}
                , {align: 'center', toolbar: '#lifeCycleTableBar', title: '操作', fixed: 'right'}

            ]],
            done: function (res, curr, count) {

            }
        });

        form.render("select");

        // 工具条点击事件
        table.on('tool(lifeCycleTable)', function (obj) {
            let data = obj.data;
            if (obj.event === 'info') {//详情
                showUsageDetailsTemplate(data);
            }
        });

        //监听排序
        table.on('sort(deviceTable)', function (obj) {
            table.reload('deviceTable', {
                initSort: obj
                , where: {
                    sort: obj.field
                    , order: obj.type
                }
            });
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}}, 'data');
        });

        // 重置搜索
        form.on('submit(resets)', data => {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            let field = data.field;
            for (let key in field) {
                field[key] = ''
            }
            insTb.reload({where: field, page: {curr: 1}}, 'data');
        });

        //使用详情
        function showUsageDetailsTemplate(_data) {
            admin.open({
                type: 1,
                area: ['1100px', '800px'],
                offset: '65px',
                title: '使用详情',
                content: $('#usageDetailsTemplate').html(),
                success: function () {
                    // 渲染表格
                    let usageDetailsTb = table.render({
                        elem: '#usageDetailsTable',
                        data: [_data],
                        cellMinWidth: 100,
                        cols: [[
                            {field: 'packLabelCode', title: '刀具条码'}
                            , {field: 'skuCode', title: '物料编号'}
                            , {field: 'skuName', title: '物料名称'}
                            , {field: 'specCode', title: '规格码'}
                        ]]
                    });
                    let timeLineData = [
                        {time: '2023-10-30 10:25:59', name: '刘景', stateName: '结果相符(报废)'},
                        {time: '2023-10-20 05:25:59', name: '刘景', stateName: '报废'},
                        {time: '2023-10-18 08:25:59', name: '刘景', stateName: '取出'},
                        {time: '2023-10-17 15:25:59', name: '刘景', stateName: '暂存'},
                        {time: '2023-10-16 19:25:59', name: '刘景', stateName: '报废'},
                        {time: '2023-10-15 11:25:59', name: '刘景', stateName: '盘验'},
                        {time: '2023-10-14 14:25:59', name: '刘景', stateName: '领新'},
                    ];

                    admin.reqSync('enterprisecab/cabinet/admin/cutterLifeCycleRecord/list', {cutterLifeCycleId: _data.id}, function (res) {
                        if (res.code === 200) {
                            timeLineData = res.data;
                        } else {
                            timeLineData = [];
                        }
                    }, 'get');


                    let htmlTpl = timeLineTemplate.innerHTML, htmlView = document.getElementById('timeline');
                    laytpl(htmlTpl).render(timeLineData, function (html) {
                        htmlView.innerHTML = html;
                    });
                }
            });

        }

        // 导出
        $('#deviceBtnExport').click(function () {
            var sTime = $('#startTime').val();
            var eTime = $('#endTime').val();

            location.href = config.base + 'enterprise/device/admin/device/export?startCreateTime=' + sTime + '&endCreateTime=' + eTime + '&enterpriseCode=' + config.getUser().enterpriseCode;
        });

    });
</script>